package com.example.lixiaomao.myapplication;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

public class LocalAdapter extends RecyclerView.Adapter {
    private ArrayList<ItemBean> mDataset;


    public LocalAdapter() {

    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View rootView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list,parent,false);
        return new LocalViewHolder(rootView);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        LocalViewHolder localViewHolder = (LocalViewHolder) holder;
        final ItemBean itemBean = mDataset.get(position);
        localViewHolder.mTitle.setText(itemBean.title);
        localViewHolder.mContent.setText(itemBean.content);
    }

    @Override
    public int getItemCount() {
        return mDataset == null ? 0 : mDataset.size();
    }


    private class LocalViewHolder extends RecyclerView.ViewHolder{
        private TextView mTitle;
        private TextView mContent;

        public LocalViewHolder(View itemView) {
            super(itemView);
            this.mTitle = itemView.findViewById(R.id.tv_title);
            this.mContent = itemView.findViewById(R.id.tv_content);
        }
    }

    public void setmDataset(ArrayList<ItemBean> mDataset) {
        this.mDataset = mDataset;
    }


}
